<template>
    <div class="top-container">
        <div class="logo">
            <router-link to="/"><img src="../../assets/images/logo.png" alt=""></router-link>
        </div>
        <div class="user">
            <div class="user-icon">
                <img :src="userStore.avatar" alt="">
            </div>
            <div class="user-text">
                <el-dropdown>
                    <span class="el-dropdown-link">
                        {{ userStore.$state.name }}
                        <el-icon class="el-icon--right">
                            <arrow-down />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="logOut">退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </div>
    </div>
</template>
<script setup>
import { ref, reactive } from "vue"
import useUserStore from '@/stores/modules/user'
import { ArrowDown } from '@element-plus/icons-vue'
import { useRouter } from "vue-router"

const userStore = useUserStore()
const router = useRouter()


const logOut = () => {
    userStore.logOut().then(res => {
        router.push("/login")
    })
}

</script>
<style lang="less" scoped>
.top-container {
    width: 100%;
    height: 60px;
    line-height: 60px;
    background: #fff;
    position: relative;
    box-shadow: 0 8px 30px rgba(0, 38, 115, 0.1);
    z-index: 999;
    display: flex;

    .logo {
        display: flex;
        justify-content: center;
        align-items: center;

        img {
            display: block;
            height: 30px;
            cursor: pointer;
        }
    }

    .user {
        flex: 1;
        display: flex;
        justify-content: flex-end;
        align-items: center;

        .user-icon {
            margin-right: 10px;

            img {
                display: block;
                width: 40px;
                height: 40px;
                border-radius: 50%;
            }
        }

        .user-text {
            line-height: 40px;
            display: flex;
            justify-content: center;
            align-items: center;

            :deep(.el-tooltip__trigger:focus-visible) {
                outline: unset;
            }

            span {
                margin-right: 10px;
                font-weight: 700;
                font-size: 16px;
            }
        }
    }
}
</style>
